package drawing;

import java.io.File;

import malaria_acd.AddNewNameActivity;

import project.malaria.malaria_acd.R;
import project.malaria.malaria_acd.R.id;
import project.malaria.malaria_acd.R.layout;

import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;

public class ImageViewerActivity2 extends Activity {
	/***Variable:: SharedPreference***/
	public static final String PREFS_NAME = "DrawingFName";
	public static  String shDrawFName;
	private  SharedPreferences share1;
	
	public static final String PREFS_NAME2 = "DrawingLName";
	public static  String shDrawLname;
	private  SharedPreferences share2;
                                                                   
	/***Variable :: Widget***/
	private ImageView back;
	
	/***Variable :: Content***/
	private String root;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_image_viewer2);
		initializeValue();
		
		String filename_fname = share1.getString(shDrawFName, "DEFAULT");
		String filename_lname = share2.getString(shDrawLname, "-");
			
	
		File imgFile_Fname = new  File(root + "/ACD/images/"+filename_fname);
		File imgFile_Lname = new  File(root + "/ACD/images/"+filename_lname);
		if(imgFile_Fname.exists() && imgFile_Lname.exists() ){

		    Bitmap myBitmap = BitmapFactory.decodeFile(imgFile_Fname.getAbsolutePath());
		    Bitmap myBitmap2 = BitmapFactory.decodeFile(imgFile_Lname.getAbsolutePath());
		    ImageView myImage = (ImageView) findViewById(R.id.viewname);
		    ImageView myImage2 = (ImageView) findViewById(R.id.viewlname);
		    myImage.setImageBitmap(myBitmap);
		    myImage2.setImageBitmap(myBitmap2);

		}
	
		else
		{
			System.out.println("IMAGE NOT FOUND!");
		}
		
		back.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
			
				 onBackPressed();
			}
		});		
	}

		public void funcEdit(View v) {		
			funcEdit();
		}
			
		public void funcEdit() {
			 Intent i = new Intent(ImageViewerActivity2.this, DrawNameActivity.class);
			 finish();
			 startActivityForResult(i,0);	
		}
	
		private void initializeValue()
		{
			share1 = this.getSharedPreferences(PREFS_NAME, 0);
			share2 = this.getSharedPreferences(PREFS_NAME2, 0);
			root = Environment.getExternalStorageDirectory().toString();
			back = (ImageView) findViewById(R.id.imageView1);
		}
}
